package observer.weatherApp.display.impl;

import observer.weatherApp.display.DisplayElement;
import observer.weatherApp.observer.Observer;
import observer.weatherApp.subject.Subject;

import java.util.ArrayList;

public class StatisticDisplay implements DisplayElement, Observer {

    private ArrayList<Float> temperatures;
    private ArrayList<Float> humidities;
    private ArrayList<Float> pressures;

    private Subject weatherData;

    public StatisticDisplay(Subject weatherData) {

        temperatures = new ArrayList<Float>();
        humidities = new ArrayList<Float>();
        pressures = new ArrayList<Float>();

        this.weatherData = weatherData;
        weatherData.registerObserver(this);

    }

    @Override
    public void display() {
        System.out.println(this);
    }

    @Override
    public void update(float temperature, float humidity, float pressure) {
        temperatures.add(temperature);
        humidities.add(humidity);
        pressures.add(pressure);
        display();
    }

    @Override
    public String toString() {
        return "StatisticDisplay{" +
                "temperatures=" + temperatures +
                ", humidities=" + humidities +
                ", pressures=" + pressures +
                '}';
    }
}
